package com.sirdc.modules.sys.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import com.sirdc.modules.core.filter.BaseFilter;
import com.sirdc.modules.sys.entity.SysDeptRoom;
import com.sirdc.modules.sys.filter.SysDeptRoomFilter;
import com.sirdc.modules.utils.ObjectUtils;
import com.sirdc.modules.utils.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class SysDeptRoomDao extends StringDao<SysDeptRoom> {

    public List<SysDeptRoom> queryDeptList(SysDeptRoomFilter filter){
        GenericQuery query = createQuery("obj");
        query.append(" and obj.state =:state").setParam("state", "02");
        if(ObjectUtils.isNotBlank(filter)){
            if(StringUtils.isNotBlank(filter.getRoomName())){
                query.append(" and obj.roomName like:roomName")
                        .setParam("roomName", StringUtils.getLikewords(filter.getRoomName()));
            }
            if(StringUtils.isNotBlank(filter.getState())){
                query.append(" and obj.state =:state").setParam("state", filter.getState());
            }else{
                //默认查询正常
                query.append(" and obj.state =:state").setParam("state", "02");
            }
            if(StringUtils.isNotBlank(filter.getDeptId())){
                query.append(" and obj.deptId =:deptId").setParam("deptId", filter.getDeptId());
            }
            if(!"".equals(filter.getFgLeader())&&null!=filter.getFgLeader())
            {
                query.append(" and obj.fgLeader=:fgLeader").setParam("fgLeader",filter.getFgLeader());
            }
        }
        query.setOrder("deptId", BaseFilter.DESC);
        query.setOrder("orderBy", BaseFilter.ASC);
        return query.listResult(filter);
    }

}
